001 /* 002 * Copyright 2005 Stephen J. McConnell 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. 014 * 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package net.dpml.library.info; 020 021 import java.util.Arrays; 022 import java.util.Properties; 023 import java.util.ArrayList; 024 025 import net.dpml.lang.Category; 026 027 /** 028 * The ModuleDirective class describes a module data-structure. 029 * 030 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 031 * @version 1.1.0 032 */ 033 public final class DependencyDirective extends AbstractDirective 034 { 035 /** 036 * BUILD scope. 037 */ 038 public static final Scope BUILD = Scope.BUILD; 039 040 /** 041 * RUNTIME scope. 042 */ 043 public static final Scope RUNTIME = Scope.RUNTIME; 044 045 /** 046 * TEST scope. 047 */ 048 public static final Scope TEST = Scope.TEST; 049 050 private final Scope m_scope; 051 private final IncludeDirective[] m_includes; 052 053 /** 054 * Creation of a new dependency directive. 055 * @param scope the scope 056 * @param includes an array of resource includes 057 */ 058 public DependencyDirective( Scope scope, IncludeDirective[] includes ) 059 { 060 this( scope, includes, null ); 061 } 062 063 /** 064 * Creation of a new dependency directive. 065 * @param scope the scope 066 * @param includes an array of resource includes 067 * @param properties supplimentary properties 068 */ 069 public DependencyDirective( Scope scope, IncludeDirective[] includes, Properties properties ) 070 { 071 super( properties ); 072 073 if( null == scope ) 074 { 075 throw new NullPointerException( "scope" ); 076 } 077 if( null == includes ) 078 { 079 throw new NullPointerException( "includes" ); 080 } 081 m_scope = scope; 082 m_includes = includes; 083 } 084 085 /** 086 * Return the dependency scope. 087 * @return the scope 088 */ 089 public Scope getScope() 090 { 091 return m_scope; 092 } 093 094 /** 095 * Return the array of resource includes associated with the dependency group. 096 * @return the includes array 097 */ 098 public IncludeDirective[] getIncludeDirectives() 099 { 100 return m_includes; 101 } 102 103 /** 104 * Return the array of resource includes associated with the dependency group 105 * filtered relative to a supplied category. 106 * @param category a runtime category argument (SYSTEM, PUBLIC, PROTECTED or PRIVATE) 107 * @return the filtered includes array 108 */ 109 public IncludeDirective[] getIncludeDirectives( Category category ) 110 { 111 if( null == category ) 112 { 113 return m_includes; 114 } 115 ArrayList list = new ArrayList(); 116 for( int i=0; i<m_includes.length; i++ ) 117 { 118 IncludeDirective include = m_includes[i]; 119 if( category.equals( include.getCategory() ) ) 120 { 121 list.add( include ); 122 } 123 } 124 return (IncludeDirective[]) list.toArray( new IncludeDirective[0] ); 125 } 126 127 /** 128 * Compare this object with another for equality. 129 * @param other the other object 130 * @return true if equal 131 */ 132 public boolean equals( Object other ) 133 { 134 if( super.equals( other ) && ( other instanceof DependencyDirective ) ) 135 { 136 DependencyDirective dep = (DependencyDirective) other; 137 if( !equals( m_scope, dep.m_scope ) ) 138 { 139 return false; 140 } 141 else 142 { 143 return Arrays.equals( m_includes, dep.m_includes ); 144 } 145 } 146 else 147 { 148 return false; 149 } 150 } 151 152 /** 153 * Compute the hash value. 154 * @return the hascode value 155 */ 156 public int hashCode() 157 { 158 int hash = super.hashCode(); 159 hash ^= super.hashArray( m_includes ); 160 hash ^= super.hashValue( m_scope ); 161 return hash; 162 } 163 }